#include<bits/stdc++.h>
using namespace std;
int n,h[100009],a[100009];
bool check(int x){
    map<int,int> mp;
    for(int i=1;i<=x;i++){
        mp[a[i]]++;
    }int sum=mp[a[x]];
    for(int i=1;i<=x;i++){
        if(a[i]==a[x]){
            break;
        }mp[a[i]]=max(0,mp[a[i]]-sum);
    }sum=n-x;
    if(a[x]==a[x+1]){
        int y=0;
        for(int i=x+1;i<=n;i++){
            if(a[i]!=a[i+1]){
                y=i;
                break;
            }
        }if(n-y<mp[a[x]]){
            return 0;
        }sum-=mp[a[x]];
    }for(map<int,int>::iterator it=mp.begin();it!=mp.end();it++){
        if(it->second==0)continue;
        if(it->first==a[x+1])break;
        sum-=(it->second);
        if(sum<0){
            return 0;
        }
    }return 1;
}int main(){
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
        h[a[i]]++;
    }sort(a+1,a+n+1);
    int l=1,r=n;
    while(l<r){
        int mid=(l+r+1)/2;
        if(check(mid)){
            l=mid;
        }else{
            r=mid-1;
        }
    }cout<<n-l;
    return 0;
}
